#!/bin/bash

cwd=$(pwd)

local_res_path=$1
rsync_res_path=$2
rsync_tfs_path=$3

echo "local_res_path: $1, rsync_res_path: $2, rsync_tfs_path: $3"

RES_ROOT_LOCAL=/data/resources/resource/olive.core.wfst/res

rsync_server=$RSYNC_SERVER
if [[ $NODENAME == d3* ]]; then
  rsync_server=$D3_RSYNC_SERVER
fi

# 同步转写资源($rsync_res_path)到宿主机
echo "rsync -rptDL $rsync_server::dui_resource/olive.core.wfst/res/$rsync_res_path $RES_ROOT_LOCAL"
rsync -rptDL $rsync_server::dui_resource/olive.core.wfst/res/$rsync_res_path $RES_ROOT_LOCAL
if [ $? -ne 0 ]; then
  echo "rsync -rptDL $rsync_server::dui_resource/olive.core.wfst/res/$rsync_res_path $RES_ROOT_LOCAL Failed"
  exit 1
fi

#建个资源的软链到$local_res_path, For JAVA
[[ -d $RES_ROOT_LOCAL/$local_res_path ]] && rm -rf $RES_ROOT_LOCAL/$local_res_path
ln -s $RES_ROOT_LOCAL/$rsync_res_path $RES_ROOT_LOCAL/$local_res_path

if [[ -n "$rsync_tfs_path" ]]; then
  # 同步CUDA资源($rsync_tfs_path)到宿主机
  rsync -rptDL $rsync_server::dui_resource/olive.core.wfst/res/cuda_res/$rsync_tfs_path $RES_ROOT_LOCAL/cuda_res
  if [ $? -ne 0 ]; then
    echo "rsync -rptDL $rsync_server::dui_resource/olive.core.wfst/res/cuda_res/$rsync_tfs_path $RES_ROOT_LOCAL Failed"
    exit 1
  fi
fi
